import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
import TableControls from '#cpt/temp/TableControls'
import Enable from '#cpt/temp/Enable'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const BtnGroup = $Lazy.load(()=>import('#tp/btn-group'))
// =====================================================================
const enabledData = [{ name:'锁定', value: '1' }, { name:'未锁定', value: '0' }]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		selectedKeys: [],
		pag: {},
	}
	
	model = {}
	
	open = ({ uuid }) => {
		this.model = {}
		this.modal.open()
		this.query ={ part_id:uuid }
		// 阻止重复加载数据
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'lis-lab-section/index')
	
	// 表单
	cols = [
		{ title: '实验号模板', 	dataIndex: 'lab_name', 		...$fn.table.spec_code },
		{ title: '实验号', 		dataIndex: 'code', 			width:80 },
		{ title: '状态', 		dataIndex: 'status_name', 	...$fn.table.time },
		{ title: '锁定状态', 	dataIndex: 'enabled', 		width:100, render:text=>$fn.getState(enabledData,text) },
		{ title: '使用者', 		dataIndex: 'real_name', 	...$fn.table.name },
		TableControls.controls.call(this, { width: 180 })
	]
	
	// 表格操作按钮
	table_controls = (text,{uuid, enabled}) => {
		return [
			+enabled === 0 && this.onEnabled(1, [uuid], false),							// 启用
			+enabled === 1 && this.onEnabled(0, [uuid], false),							// 禁用
		]
	}
	controls = () => {
		return [
			this.onEnabled(1,this.state.selectedKeys, true),		// 锁定
			this.onEnabled(0,this.state.selectedKeys, true)			// 解锁
		]
	}
	
	// 禁用/启用
	onEnabled = (status, uuids, isKeys) => Enable.call(this, status, { label1:'锁定', label2:'解锁', query:{ status, uuids }, isKeys, api:'lis-lab-section-part/singlebind' } )
	
	render(){
		return TableModal.call(this,{ title: '实验号分段详情', labelWidth:'s7', width:'60%', height:'60%', noSubmit:true,
			prefix:(
				<div className='fxr mb5'>
					<BtnGroup controls={this.controls()} />
				</div>
				
			)
		})
	}
}

export default Index